<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
		xmlns:h="http://java.sun.com/jsf/html"  
		xmlns:f="http://java.sun.com/jsf/core"
		xmlns:ui="http://java.sun.com/jsf/facelets"
		xmlns:c="http://java.sun.com/jsp/jstl/core">  
    
    <ui:composition template="#{helperNavigation.getPathTemplate('administration')}">
        <ui:define name="pageTitle">Edition d'un livre</ui:define>
        
        <ui:define name="mainContent">
            <h:form id="formEditBook">
                <h:panelGrid columns="2">
                    <h:panelGrid columns="1">
                        <h2>Edition d'un livre</h2>
                        <h3><h:outputText value="Titre :" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.title}" />
                        
                        <h3><h:outputText value="Catégorie :" /></h3>
                        <h:selectOneMenu value="#{userSession.book.category}">
                            <f:selectItems value="#{bookManager.getCategoriesEnum()}"/>
                        </h:selectOneMenu>
                        
                        <h3><h:outputText value="Editeur :" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.editor}" />

                        <h3><h:outputText value="Date de publication :" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.publicationDate}"><f:convertDateTime pattern="dd/MM/YYYY" /></h:inputText>

                        <h3><h:outputText value="Prix :" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.price}" />

                        <h3><h:outputText value="Stock :" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.stock}" />

                        <h3><h:outputText value="Seuil" /></h3>
                        <h:inputText class="validate[required]" value="#{userSession.book.threshold}" />

                        <h3><h:outputText value="Résumé :" /></h3>
                        <h:inputTextarea class="validate[required]" value="#{userSession.book.summary}" />

                        <h3><h:outputText value="Sommaire :" /></h3>
                        <h:inputTextarea class="validate[required]" value="#{userSession.book.contents}" />

                        
                        <c:if test="#{userSession.book.authors == null}">
                            <h:commandButton value="Ajouter" action="#{bookManager.addBook(userSession.book)}" styleClass="btn btn-success marginLeft150Px" />
                        </c:if>
                        <c:if test="#{userSession.book.authors != null}">
                            <h:commandButton value="Modifier" action="#{bookManager.updateBook(userSession.book)}" styleClass="btn btn-success marginLeft150Px" />
                        </c:if>
                        <h:commandButton value="Annuler" action="administrationBooks?faces-redirect=true" styleClass="btn btn-warning red" />
                    </h:panelGrid>
                    
                    <h:panelGrid>
                        <h2>Gestion des auteurs</h2>
                        
                        <h3><h:outputText value="Auteur(s) :" /></h3>
                        <h:selectManyListbox value="#{userSession.authorsId}">
                            <f:selectItems value="#{bookManager.getAllAuthors()}" var="auth" itemValue="#{auth.id}" itemLabel="#{auth.firstName} #{auth.lastName}" />
                        </h:selectManyListbox>
                        <h:form id="formCreateAuthor">
                            <h3><h:outputText value="Prénom :" /></h3>
                            <h:inputText value="#{bookManager.firstName}" />

                            <h3><h:outputText value="Nom :" /></h3>
                            <h:inputText value="#{bookManager.lastName}" />
                            <br />
                            
                            <h:commandButton value="Ajouter" action="#{bookManager.addAuthor()}" styleClass="btn btn-primary marginLeft150Px"/>
                        </h:form>
                    </h:panelGrid>
                </h:panelGrid>
            </h:form>
            
            <script type="text/javascript">
                $j(function(){
                    var form = "#formEditBook";

                    // Load validationEngine for check in real time the user entries.
                    $j(form).validationEngine('attach');
                });

            </script>
        </ui:define>
    </ui:composition>
</html>
